package org.example.sec10.respository;

import java.util.Collections;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class AccountRespository {
    private static final Map<Integer, Integer> DB = IntStream.rangeClosed(1, 10)
            .boxed().collect(Collectors.toConcurrentMap(
                    Function.identity()
                    , v -> 100
            ));

    public static Integer getBalance(int account) {
        return DB.get(account);
    }

    public static void deductAccount(int accNUm, int amount) {
        DB.computeIfPresent(accNUm, (k, v) -> v - amount);
    }

    public static Map<Integer, Integer> getAllAccounts() {
        return Collections.unmodifiableMap(DB);
    }

    public static void addAmount(int toAccount, int amount) {
        DB.computeIfPresent(toAccount, (k, v) -> v + amount);
    }
}
